﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace FirstGame
{
    public class ScreenManager
    {
        List<GameScreen> _Screens;

        public List<GameScreen> Screens
        {
            get { return _Screens; }
            set { _Screens = value; }
        }

        private IntroScreen _Introscreen;

        public IntroScreen Introscreen
        {
            get { return _Introscreen; }
            set { _Introscreen = value; }
        }

        private MainMenuScreen _Mainmenuscreen;

        public MainMenuScreen Mainmenuscreen
        {
            get { return _Mainmenuscreen; }
            set { _Mainmenuscreen = value; }
        }
        private SettingScreen _Settingscreen;

        public SettingScreen Settingscreen
        {
            get { return _Settingscreen; }
            set { _Settingscreen = value; }
        }
        InputSystem _Input;

        public InputSystem Input
        {
            get { return _Input; }
            set { _Input = value; }
        }

        
        public ScreenManager(ContentManager content)
        {
            Screens = new List<GameScreen>();
            Input = new InputSystem();
             _Introscreen= new IntroScreen(content, "BackgroundTexture\\background4", Vector2.Zero);
             _Introscreen.Exited += new EventHandler(_Introscreen_Exited);
             Screens.Add(_Introscreen);

            string[] strTextures0 = { "TextureMenuItems\\newgame1", "TextureMenuItems\\continue1", "TextureMenuItems\\setting1", "TextureMenuItems\\exit1" };
            string[] strTextures1 = { "TextureMenuItems\\newgame2", "TextureMenuItems\\continue2", "TextureMenuItems\\setting2", "TextureMenuItems\\exit2" };
            _Mainmenuscreen = new MainMenuScreen(content, this, "BackgroundTexture\\background", strTextures0, strTextures1, new Vector2(100, 50));


            _Mainmenuscreen.ScreenState = ScreenState.InActive;
            _Mainmenuscreen.TransitionOnTime = TimeSpan.FromSeconds(2);
            Screens.Add(_Mainmenuscreen);

            _Settingscreen = new SettingScreen(content, "TextureMenuItems\\setting", new Vector2(400, 50), new Vector2(250,300));
            _Settingscreen.ScreenState = ScreenState.InActive;
            _Settingscreen.TransitionPercent = 0.3f;
            
            Screens.Add(_Settingscreen);
            

            


        }

        void _Introscreen_Exited(object sender, EventArgs e)
        {
            _Mainmenuscreen.ScreenState = ScreenState.TransitionOn;
        }


        public void Update(GameTime gameTime)
        {
            Input.Update();
            //Introscreen.Update(gameTime, _Input);
            
            foreach (GameScreen screen in Screens)
            {
                if (screen.ScreenState != ScreenState.InActive)
                    screen.Update(gameTime, Input);
            }
            
             
        }

        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            foreach (GameScreen screen in Screens)
            {
                if (screen.ScreenState != ScreenState.InActive)
                    screen.Draw(gameTime, spriteBatch);
            }
           
        }
    }
}
